package content
{
	import _Pan3D.core.MathCore;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.text.TextField;

	public class FileListView extends MovieClip
	{
		private var _w:int=270;
		private var _h:int=400;
		private var _list:List;
		private var _fileItem:Array;
		private var _showBitmap:Bitmap;
		private var _lastMouseDownX:Number;
		private var _listTitleBar:ListTitleBar;


		public function FileListView()
		{
			addBacks();
			addTexts();
			addLists();
			addMoveBitmap();
			addEvents();
		}

		private function addMoveBitmap():void
		{
			_showBitmap=new Bitmap;
			_showBitmap.visible=false;
			addChild(_showBitmap);
			_showBitmap.x=300;
		}

		private function addEvents():void
		{
			UiManege.stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp)
			UiManege.stage.addEventListener(MouseEvent.MOUSE_MOVE, stageMouseMove)
			this.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseWheel)
	
		}
		protected function onMouseWheel(event:MouseEvent):void
		{
			_list.listScroll.speedNum(-event.delta);
			
		}

		protected function stageMouseMove(event:MouseEvent=null):void
		{
			if (UiManege.isMoveFileNow)
			{
				_showBitmap.x=mouseX - _lastMouseDownX + 20;
				_showBitmap.y=mouseY - 15;
				_showBitmap.visible=true;

				//将要移动的文件，半透明

				_list.setMoveAllCellAphal(UiManege.isMoveModelVo.id)
			}
		}

		protected function stageMouseUp(event:MouseEvent):void
		{
			_showBitmap.visible=false;
			UiManege.isMoveFileNow=false;
			_list.setMoveAllCellAphal(99999)
		}

		public function changeModelVoFather(fatherId:uint):void
		{

			if (UiManege.isMoveModelVo && _showBitmap.visible)
			{
				if (UiManege.isMoveModelVo.id != fatherId)
				{
					var canMove:Boolean=_list.isItSonAndCamMove(UiManege.isMoveModelVo.id, fatherId)
					if (canMove)
					{
						UiManege.isMoveModelVo.father=fatherId;
						_list.changePasition()
					}
				}
			}
		}

		public function moveModelvo(vo:ModelVO):void
		{

			var tempBitMapData:BitmapData=new BitmapData(300, vo.bh, true, 0x000000);
			var m:Matrix=new Matrix;
			m.ty=-vo.by;
			_list.allCell.mask=null;
			tempBitMapData.draw(_list.allCell, m);
			_showBitmap.bitmapData=tempBitMapData;
			_list.allCell.mask=_list.maskMc;
			_lastMouseDownX=mouseX;
			UiManege.isMoveFileNow=true;
			UiManege.isMoveModelVo=vo;

		}

		private function addLists():void
		{
			_listTitleBar=new ListTitleBar;
			_listTitleBar.x=10;
			_listTitleBar.y=10;
			addChild(_listTitleBar);
			
			_list=new List();
			addChild(_list);
			_list.x=15;
			_list.y=40;
			
			 UiManege.fileList=_list
		}

		private function addTexts():void
		{
			var titleTxt:TextField=TextUtil.getTextField();
			titleTxt.htmlText="场景模型列表";
			addChild(titleTxt);
			titleTxt.x=15;
			titleTxt.y=15;
		}

		public function upDataXml(xml:XML):void
		{
			_fileItem=new Array;
			var _item:Array=MathCore.getSourcePro(xml);
			for (var i:int=0; i < _item.length; i++)
			{
				var tempModelVo:ModelVO=new ModelVO;
				tempModelVo.name=_item[i].name;
				tempModelVo.id=_item[i].id;
				tempModelVo.open=(_item[i].open == 1);
				tempModelVo.filetype=_item[i].filetype;
				tempModelVo.father=_item[i].father;
				tempModelVo.bh=DataType.NUM25
				_fileItem.push(tempModelVo)
			}
			_list.source(_fileItem);
		}

		private function addBacks():void
		{
			var backPic:Shape=new Shape;
			addChild(backPic);
			backPic.graphics.beginFill(0x003c00, 1);
			backPic.graphics.drawRect(0, 0, _w, _h);
			backPic.graphics.endFill();

			var backBox:Shape=new Shape;
			addChild(backBox);

			backBox.graphics.beginFill(0xffffff, 0.9);
			backBox.graphics.drawRect(0 + 10, 0 + 40, _w - 20, _h - 80);
			backBox.graphics.endFill();


		}
	}
}
